<template>
  <div class="p-2">
    <!--查询区域-->
    <div class="jeecg-basic-table-form-container">
      <a-form ref="formRef" @keyup.enter.native="searchQuery" :model="queryParam" :label-col="labelCol" :wrapper-col="wrapperCol">
        <a-row :gutter="24">
          <a-col :lg="6">
            <a-form-item name="riskDeviceId">
              <template #label><span title="风险分析装置">风险分析对象</span></template>
              <j-dict-select-tag placeholder="请选择风险分析装置" v-model:value="queryParam.riskDeviceId" dictCode="tb_base_risk_device,name,id"/>
            </a-form-item>
          </a-col>
          <a-col :lg="6">
            <a-form-item>
               <template #label><span title="排查时间">排查时间</span></template>
               <div style="display: flex">
                 <a-form-item name="startDate" style="margin-bottom: 0;">
                   <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间" v-model:value="queryParam.startDate" class="query-group-cust" />
                 </a-form-item>
                 <span class="query-group-split-cust">~</span>
                 <a-form-item name="endDate" style="margin-bottom: 0;">
                   <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间" v-model:value="queryParam.endDate" class="query-group-cust" />
                 </a-form-item>
               </div>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-col :lg="6">
                <a-button type="primary" preIcon="ant-design:search-outlined" @click="searchQuery">查询</a-button>
                <a-button type="primary" preIcon="ant-design:reload-outlined" @click="searchReset" style="margin-left: 8px">重置</a-button>
              </a-col>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!--引用表格-->
    <BasicTable @register="registerTable" :rowSelection="rowSelection">
      <!--插槽:table标题-->
      <!--操作栏-->
      <!-- <template #action="{ record }">
        <TableAction :actions="getTableAction(record)"/>
      </template>
      <template v-slot:bodyCell="{ column, record, index, text }">
      </template> -->
    </BasicTable>
    <!-- 表单区域 -->
  </div>
</template>

<script lang="ts" name="TbBaseMeasuresTaskRecord-tbBaseMeasuresTaskRecord" setup>
  import { ref, reactive } from 'vue';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { superQuerySchema } from './TbBaseMeasuresTaskRecord.data';
  import { queryCountListByRiskDevice, deleteOne, batchDelete, getImportUrl, getExportUrl } from './TbBaseMeasuresTaskRecord.api';
  import { downloadFile } from '/@/utils/common/renderUtils';
  import { useUserStore } from '/@/store/modules/user';
  import JDictSelectTag from '/@/components/Form/src/jeecg/components/JDictSelectTag.vue';
  import JSelectUser from '/@/components/Form/src/jeecg/components/JSelectUser.vue';
  
  const columns: BasicColumn[] = [
    {
      title: '装置名称',
      dataIndex: 'name',
      width: 200,
    },
    {
      title: '主要负责人',
      children: [
        {
          title: '任务次数',
          dataIndex: 'mainTaskSum',
          width: 120,
        },
        {
          title: '待排查次数',
          dataIndex: 'mainWaitCount',
          width: 120,
        },
        {
          title: '超期次数',
          dataIndex: 'mainDueCount',
          width: 120,
        },
      ],
    },
    {
      title: '技术负责人',
      children: [
        {
          title: '任务次数',
          dataIndex: 'technologyTaskSum',
          width: 120,
        },
        {
          title: '待排查次数',
          dataIndex: 'technologyWaitCount',
          width: 120,
        },
        {
          title: '超期次数',
          dataIndex: 'technologyDueCount',
          width: 120,
        },
      ],
    },
    {
      title: '操作负责人',
      children: [
        {
          title: '任务次数',
          dataIndex: 'operateTaskSum',
          width: 120,
        },
        {
          title: '待排查次数',
          dataIndex: 'operateWaitCount',
          width: 120,
        },
        {
          title: '超期次数',
          dataIndex: 'operateDueCount',
          width: 120,
        },
      ],
    },
  ];
  const formRef = ref();
  const queryParam = reactive<any>({});
  const registerModal = ref();
  const userStore = useUserStore();
  //注册table数据
  const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
    tableProps: {
      title: '重大危险源包保责任人风险排查任务统计',
      api: queryCountListByRiskDevice,
      columns,
      canResize:false,
      useSearchForm: false,
      actionColumn: {
        width: 120,
        fixed: 'right',
      },
      beforeFetch: (params) => {
        return Object.assign(params, queryParam);
      },
    },
	  importConfig: {
	    url: getImportUrl,
	    success: handleSuccess
	  },
  });
  const [registerTable, { reload, collapseAll, updateTableDataRecord, findTableDataRecord, getDataSource }, { rowSelection, selectedRowKeys }] = tableContext;
  const labelCol = reactive({
    xs:24,
    sm:4,
    xl:6,
    xxl:4
  });
  const wrapperCol = reactive({
    xs: 24,
    sm: 20,
  });

  // 高级查询配置
  const superQueryConfig = reactive(superQuerySchema);

  /**
   * 高级查询事件
   */
  function handleSuperQuery(params) {
    Object.keys(params).map((k) => {
      queryParam[k] = params[k];
    });
    searchQuery();
  }
   
  /**
   * 成功回调
   */
  function handleSuccess() {
    (selectedRowKeys.value = []) && reload();
  }

  /**
   * 查询
   */
  function searchQuery() {
    reload();
  }
  
  /**
   * 重置
   */
  function searchReset() {
    formRef.value.resetFields();
    selectedRowKeys.value = [];
    //刷新数据
    reload();
  }
  
  /**
   * form点击事件(以逗号分割)
   * @param key
   * @param value
   */
  function handleFormJoinChange(key, value) {
    queryParam[key] = value.join(',');
  }


</script>

<style lang="less" scoped>
  .jeecg-basic-table-form-container {
    padding: 0;
    .table-page-search-submitButtons {
      display: block;
      margin-bottom: 24px;
      white-space: nowrap;
    }
    .query-group-cust{
      min-width: 100px !important;
    }
    .query-group-split-cust{
      width: 30px;
      display: inline-block;
      text-align: center
    }
  }
</style>
